package com.kuang.bascic.service;

import com.kuang.bascic.mapper.BaseMapper;
import com.kuang.bascic.query.BaseQuery;
import com.kuang.bascic.utils.PageList;
import com.kuang.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements BaseService<T>{
    @Autowired
    private BaseMapper<T> mapper;
    @Override
    public List<T> selectAllDepartment() {
       return mapper.selectAllDepartment();
    }

    @Override
    public T selectDepartmentById(Long id) {
        return mapper.selectDepartmentById(id);
    }
    @Transactional
    @Override
    public void UpdateDepartment(T t) {
        mapper.UpdateDepartment(t);
    }
    @Transactional
    @Override
    public void addDepartment(T t) {
        mapper.addDepartment(t);
    }
    @Transactional
    @Override
    public void deleteDepartmentById(Long id) {
        mapper.deleteDepartmentById(id);
    }

    @Override
    public PageList<T> pageList(BaseQuery query) {
        PageList<T> list = new PageList<>();
        //传入查询分页信息并设置
        List<T> rows = mapper.selectByPage(query);
        list.setRow(rows);
        //查询条数
        Long aLong = mapper.selectCountAll(query);
        list.setTotal(aLong);
        return list;

    }
    @Transactional
    @Override
    public void PatchDelete(List id) {
        mapper.PatchDelete(id);
    }
}
